package com.magic.gre.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.magic.gre.R;
import com.magic.gre.entity.WordsBean;
import com.magic.gre.ui.activity.WordsDetailsActivity2;
import com.noname.lib_base_java.adapter.CommonAdapter;
import com.noname.lib_base_java.adapter.ViewHolder;

import java.util.List;

/**
 * Author: Lmoumou
 * Date: 2019-01-17 19:54
 * 文件名: SearchAdapter
 * 描述:
 */
public class SearchAdapter extends CommonAdapter<WordsBean> {
    public SearchAdapter(Context mContext, List<WordsBean> mData) {
        super(mContext, mData, R.layout.item_search);
    }

    @Override
    protected void bindData(ViewHolder holder, int position) {
        final WordsBean bean = mData.get(position);
        TextView wordsTv = holder.getView(R.id.words_tv);
        String content = bean.getName();
        SpannableString spannableString = new SpannableString(content);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF8652")), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        wordsTv.setText(spannableString, TextView.BufferType.SPANNABLE);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WordsDetailsActivity2.startThis(mContext,bean.getId());
            }
        });
    }
}
